<?php
  require_once("../includes.php"); 

  $action     = $_POST['action'];
  $voornaam   = trim($_POST['voornaam']);
  $achternaam = trim($_POST['achternaam']);
  $email      = trim($_POST['email']);

  $select = explode(" ", $_POST['keuze']);
  $id = $select[0];

  if ($action == "delete" && $id > 0)
  {
    if (User::delete_user($id))
      $message = true;
  }
  else if ($action == "delete")
  {
    $user = User::by_name($voornaam, $achternaam);

    if (User::delete_user($user->ID))
      $message = true;
  }
  else if ($action == "edit")
  {
    if (User::edit_user($id, $voornaam, $achternaam, $email))
      $message = true;
  }
  else
  {
    if (User::add_user($voornaam, $achternaam, $email))
      $message = true;
  }

  $url = BASE_URL;
  header("Location: $url/user/$action.php?success=$message");
?>
